package com.chazaqdev.meatbagsorter.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

import com.chazaqdev.meatbagsorter.gwt.client.PhotoServiceAsync;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Application implements EntryPoint {
	PhotoSorter photoSorter;
    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
    	
    	photoSorter = new PhotoSorter();
    	RootPanel.get().add(photoSorter);
    	
    	photoSorter.startImageSorting();
    	
//    	Button button = new Button("Click me!");
//    	button.addClickHandler(new ClickHandler() {
//			
//			@Override
//			public void onClick(ClickEvent event) {
//
//		    	photoService = (PhotoServiceAsync) GWT.create(PhotoService.class);
//		    	ServiceDefTarget endpoint = (ServiceDefTarget) photoService;
//				String moduleRelativeURL = GWT.getModuleBaseURL() + "rpc"; 
//				endpoint.setServiceEntryPoint(moduleRelativeURL);
//				
//		    	photoService.getNextUnsortedPhotoAndLockIt(new AsyncCallback() {
//		    		public void onFailure(Throwable arg0) {
//		                Window.alert("Fail");
//		            }
//
//		            public void onSuccess(Object photo) {
//		                    Window.alert("Hello");
//		            }
//				});	
//			}
//		});
//    	RootPanel.get().add(button);
    }
}
